package com.wc.算法基础课.A第一讲基础算法.双指针.牛的学术圈I;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/5 9:20
 * @description https://www.acwing.com/problem/content/description/3748/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] exNum = new int[N];
    static int[] num = new int[N];
    static int[] a = new int[N];
    static int n, l;

    public static void main(String[] args) {
        n = sc.nextInt();
        l = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
            num[a[i]]++;
        }
        for (int i = 1; i <= n; i++) {
            int l = 1;
            int r = a[i];
            exNum[l] += 1;
            exNum[r + 1] -= 1;
        }
        for (int i = 1; i < N; i++) exNum[i] += exNum[i - 1];
        int res = 0;
        for (int i = 1; i < N; i++) {
            if (exNum[i] >= i) {
                res = i;
            } else {
                if (num[i - 1] >= i - exNum[i] && l >= i - exNum[i]) {
                    res = i;
                    l -= i - exNum[i];
                } else break;
            }
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
